import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { clearRequest } from '../third-plugins/axios/interruptRequest'
// import routerName from './routerName'

const mainRoutes: RouteRecordRaw[] = [
  {
    path: '/GISMap',
    name: 'GISMap',
    component: () => import('@/views/GIS/GISMap.vue'),
  }
]


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/main',
      name: 'main',
      component: () => import('@/views/Main.vue'),
      redirect: '/GISMap',
      children: [...mainRoutes]
    },
    // 匹配不存在的页面
    {
      path: '/:pathMatch(.*)',
      redirect: {
        path: '/main',
      },
    },
  ],
})

router.beforeEach((to, from, next) => {
  clearRequest() // 路由切换时，取消上个路由的所有请求
  // 判断用户是否登录
  // const token = localStorage.getItem(
  //   localStorage.getItem("tokenName") + "_token"
  // );
  // if (!token) {
  //   // 如果去登录页面让登录
  //   if (to.name === "login") {
  //     next();
  //   } else {
  //     next({ name: "login" });
  //   }
  // } else {
  //   next();
  // }

  next()
})

export default router
